﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Umbraco.Core.Persistence;
using Umbraco.Web;
using UmbracoExtending.District.Model;

namespace UmbracoExtending.District
{
    /// <summary>
    /// 行政区域工具
    /// </summary>
    public static class DistrictUtil
    {
        /// <summary>
        /// 解析地址信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static DistrictInfo ResolveDistrict(string code)
        {
            var db = ApplicationContext.Current.DatabaseContext.Database;
            var query = new Sql().Select("ProvinceCode, ProvinceName, CityCode, CityName, DistrictCode, DistrictName, AliasName")
                .From("[umbracoExtendingDistrict]")
                .Where("[DistrictCode] = @0", code);
            return db.SingleOrDefault<DistrictInfo>(query);
        }
    }
}
